﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using MyHelper;

namespace weighing
{
    public class PhoneFormatConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (RegexHelper.IsMobilePhoneNumber((String)value)) {
                var phone = (string)value;
                return phone.Substring(0,3)+ " "+phone.Substring(3, 4)+ " " +phone.Substring(7, 4);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var phone = (string)value;
            return phone.Replace(" ", "");
        }
    }
}
